package org.uoss.applications.framework.dao.util;

import org.uoss.applications.framework.dao.model.QueryModel;

public final class DAOCriteria
{

	public final static String ORDER_ASC = "ASC";
	public final static String ORDER_DESC = "DESC";

	/**
	 * Getting the max fetching size.
	 * 
	 * @param queryModel
	 * @return
	 */
	public static Integer getMaxFetchSize(QueryModel queryModel)
	{
		return queryModel != null ? queryModel.getPageSize() : 15;
	}

	/**
	 * Getting the fetching index.
	 * 
	 * @param queryModel
	 * @return
	 */
	public static Integer getFetchIndex(QueryModel queryModel)
	{
		int fetchSize = getMaxFetchSize(queryModel);
		int pageNum = queryModel != null && queryModel.getPageIndex() > 0 ? queryModel.getPageIndex() : 1;
		return (pageNum - 1) * fetchSize;
	}
}
